using System.Collections.Generic;
using SmartClientPlatform.OMS.CommonLibrary;
using SmartClientPlatform.RemoteClientBase;
using System.Linq;

namespace WcfService1
{
    public class OMSFacade
    {
        public List<OrderDto> GetOrders()
        {
            using(var context = new OMSDataContext())
            {
                var orderScope = (from order in context.Orders
                                  select order).ToScope(context);

                orderScope.Rel(x => x.OrderDetails).Rel(x => x.Product);
                orderScope.Rel(x => x.Customer);

                return orderScope.GetDtoList(() => new OrderDto());
            }
        }

        public List<OrderDto> GetOrders2()
        {
            using (var context = new OMSDataContext())
            {
                var orderScope = (from order in context.Orders
                                  select order).ToScope(context);

                orderScope
                    .Field(x => x.OrderID)
                    .Field(x => x.OrderDate)
                    .Field(x => x.ShipDate)
                    .Rel(x => x.OrderDetails)
                    .Field(x => x.Price)
                    .Field(x => x.Quantity)
                    .Rel(x => x.Product)
                    .Field(x => x.Name);
                orderScope.Rel(x => x.Customer);

                return orderScope.GetDtoList(() => new OrderDto());
            }
        }
    }
}